/**
 * Copyright &copy; com.nmf
 */
package com.nmf.site.biz.ipn.gen.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.nmf.site.common.config.Global;
import com.nmf.site.common.persistence.Page;
import com.nmf.site.common.web.BaseController;
import com.nmf.site.common.utils.StringUtils;
import com.nmf.site.biz.ipn.gen.entity.BizFunIpn;
import com.nmf.site.biz.ipn.gen.service.BizFunIpnService;

/**
 * IPN信息Controller
 * @author 北冥
 * @version 2018-03-22
 */
@Controller
@RequestMapping(value = "${adminPath}/gen/bizFunIpn")
public class BizFunIpnController extends BaseController {

	@Autowired
	private BizFunIpnService bizFunIpnService;
	
	@ModelAttribute
	public BizFunIpn get(@RequestParam(required=false) String id) {
		BizFunIpn entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bizFunIpnService.get(id);
		}
		if (entity == null){
			entity = new BizFunIpn();
		}
		return entity;
	}
	
	@RequiresPermissions("gen:bizFunIpn:view")
	@RequestMapping(value = {"list", ""})
	public String list(BizFunIpn bizFunIpn, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BizFunIpn> page = bizFunIpnService.findPage(new Page<BizFunIpn>(request, response), bizFunIpn); 
		model.addAttribute("page", page);
		return "ipn/gen/bizFunIpnList";
	}

	@RequiresPermissions("gen:bizFunIpn:view")
	@RequestMapping(value = "form")
	public String form(BizFunIpn bizFunIpn, Model model) {
		model.addAttribute("bizFunIpn", bizFunIpn);
		return "ipn/gen/bizFunIpnForm";
	}

	@RequiresPermissions("gen:bizFunIpn:edit")
	@RequestMapping(value = "save")
	public String save(BizFunIpn bizFunIpn, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bizFunIpn)){
			return form(bizFunIpn, model);
		}
		bizFunIpnService.save(bizFunIpn);
		addMessage(redirectAttributes, "保存IPN信息成功");
		return "redirect:"+Global.getAdminPath()+"/gen/bizFunIpn/?repage";
	}
	
	@RequiresPermissions("gen:bizFunIpn:edit")
	@RequestMapping(value = "delete")
	public String delete(BizFunIpn bizFunIpn, RedirectAttributes redirectAttributes) {
		bizFunIpnService.delete(bizFunIpn);
		addMessage(redirectAttributes, "删除IPN信息成功");
		return "redirect:"+Global.getAdminPath()+"/gen/bizFunIpn/?repage";
	}

}